using WeatherSystem.API.Models;

namespace WeatherSystem.API.BackgroundJobs
{
    /// <summary>
    /// 后台作业服务接口
    /// </summary>
    public interface IBackgroundJobService
    {
        /// <summary>
        /// 立即执行数据采集任务
        /// </summary>
        Task<string> EnqueueDataCollectionAsync();

        /// <summary>
        /// 为特定城市执行数据采集
        /// </summary>
        Task<string> EnqueueCityDataCollectionAsync(Guid cityId);

        /// <summary>
        /// 执行统计生成任务
        /// </summary>
        Task<string> EnqueueStatisticsGenerationAsync();

        /// <summary>
        /// 执行数据清理任务
        /// </summary>
        Task<string> EnqueueDataCleanupAsync();

        /// <summary>
        /// 生成天气报告
        /// </summary>
        Task<string> EnqueueWeatherReportGenerationAsync(Guid cityId, DateTime startDate, DateTime endDate);

        /// <summary>
        /// 批量模拟数据生成
        /// </summary>
        Task<string> EnqueueBulkDataSimulationAsync(int recordsPerCity, double baseTemperature);

        /// <summary>
        /// 缓存预热任务
        /// </summary>
        Task<string> EnqueueCacheWarmupAsync();

        /// <summary>
        /// 定期任务调度设置
        /// </summary>
        void SetupRecurringJobs();

        /// <summary>
        /// 获取作业状态
        /// </summary>
        Task<object> GetJobStatusAsync(string jobId);

        /// <summary>
        /// 取消作业
        /// </summary>
        Task<bool> CancelJobAsync(string jobId);

        /// <summary>
        /// 获取作业统计信息
        /// </summary>
        Task<object> GetJobStatisticsAsync();
    }

    /// <summary>
    /// 后台作业任务类型枚举
    /// </summary>
    public enum BackgroundJobType
    {
        DataCollection,
        StatisticsGeneration,
        DataCleanup,
        WeatherReportGeneration,
        DataSimulation,
        CacheWarmup
    }

    /// <summary>
    /// 作业执行结果
    /// </summary>
    public class JobExecutionResult
    {
        public bool Success { get; set; }
        public string Message { get; set; } = "";
        public int ProcessedCount { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public TimeSpan Duration => EndTime - StartTime;
        public string? JobId { get; set; }
        public Dictionary<string, object> Data { get; set; } = new();
    }
}